package com.edu.activitysintent02;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

	private Button mybutton = null; 
	private TextView myTextView = null;
	private EditText myEditText1 = null;
	private EditText myEditText2 = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mybutton = (Button)this.findViewById(R.id.button1);
		
		myTextView = (TextView)this.findViewById(R.id.textView1);
		
		myEditText1 = (EditText)this.findViewById(R.id.editText1);
		
		myEditText2 = (EditText)this.findViewById(R.id.editText2);
		
	//	mybutton.setText("计算");
	//	myTextView.setText("+");
		
		mybutton.setText(R.string.calc);
		myTextView.setText(R.string.symbol);
		
		//myEditText1.setText("1");
	//	myEditText2.setText("2");
		
		mybutton.setOnClickListener(new MyButtonListener());
		
	}
	
	class MyButtonListener implements OnClickListener{

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			String num1 = myEditText1.getText().toString();
			String num2 = myEditText2.getText().toString();
			
			Intent myIntent = new Intent();
			myIntent = myIntent.putExtra("num1", num1);
			myIntent = myIntent.putExtra("num2", num2);
			
			myIntent.setClass(MainActivity.this, ResultActivity.class);
			
			MainActivity.this.startActivity(myIntent);
			
		}
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		menu.addSubMenu(0, 1, 1, "退出");
		menu.add(0,2,2,"关于");
		
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		// TODO Auto-generated method stub
		if( item.getItemId()==1 )
			finish();
		return super.onMenuItemSelected(featureId, item);
	}

}
